﻿using System;
using System.Collections;
using System.Data;
using BEGDC.CC.BL.Workflow;
using BEGDC.CC.Entity;
using NHibernate;

namespace BEGDC.CC.BL.Common.Query
{
    /// <summary>
    /// Summary description for IQuery.
    /// </summary>
    public interface IQuery
    {
        int GetMaxIdForEZVisit(int applicationStatus);

        #region Query Functions added by Joe

        int GetMaxAppID(string flowType, bool isSave);

        /// <summary>
        /// Get application object by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Application GetAppById(int id);

        /// <summary>
        /// Get Tasks
        /// </summary>
        /// <returns>Task List</returns>
        DataTable QueryTaskList(string employeeno, string employeeId, string type, bool isBacker);

        DataTable QueryTaskList(string employeeno, string employeeId, string type);

        DataTable QueryEZVTasks(string employeeName, string appNo, string departmentId);

        /// <summary>
        /// get tasks by search
        /// </summary>
        /// <param name="rolenames"></param>
        /// <param name="type"></param>
        /// <param name="departmentid"></param>
        /// <param name="appno"></param>
        /// <returns></returns>
        DataTable QueryTaskList(string employeeno, string rolenames, string type, string departmentid, string appno, bool isBacker);

        DataTable QueryTaskList(string employeeno, string rolenames, string type, string departmentid, string appno);

        /// <summary>
        /// search Tasks
        /// </summary>
        /// <returns>Task List</returns>
        /// 		DataTable QueryTaskList(string employeeId, string type, string department, string appno);
        /// <summary>
        /// Get draft
        /// </summary>
        /// <returns>Task List</returns>
        DataTable QueryMyDraftList(string employeeId, string type);

        /// <summary>
        /// Get all aps by there application id
        /// </summary>
        /// <param name="appID"></param>
        /// <returns></returns>
        DataTable QueryAPListByMeetingID(int meetingID);

        /// <summary>
        /// Get all attendee of application's EV Meeting
        /// </summary>
        /// <param name="appID"></param>
        /// <returns></returns>
        DataTable QueryEVMeetingAttendee(int meetingID);

        /// <summary>
        /// Get all attendee of application's EV Meeting by there company
        /// </summary>
        /// <param name="appID"></param>
        /// <param name="isASB"></param>
        /// <returns></returns>
        DataTable QueryEVMeetingAttendee(int appID, bool isASB);

        /// <summary>
        /// Get all attendee of a EV Meeting
        /// </summary>
        /// <param name="meetingID"></param>
        /// <returns></returns>
        DataTable QueryEVMeetingAttendeeByMeetingID(int meetingID);

        /// <summary>
        /// Get all attendee of a EV Meeting by there company
        /// </summary>
        /// <param name="meetingID"></param>
        /// <param name="isASB"></param>
        /// <returns></returns>
        DataTable QueryEVMeetingAttendeeByMeetingID(int meetingID, bool isASB);

        /// <summary>
        ///
        /// </summary>
        /// <param name="dicType"></param>
        /// <returns></returns>
        DataTable GetDicItemByTypeName(string dicType);

        /// <summary>
        /// Get categoryName by province name
        /// </summary>
        /// <param name="province">province name</param>
        /// <returns>Category Name</returns>
        string GetClusterByProvinceName(string province);

        /// <summary>
        /// Get the list which contains category name and province name
        /// </summary>
        /// <param name="catOrProvince">Decided to return CAT or province</param>
        /// <returns>Category and Province List</returns>
        DataTable GetPCATNameList(bool catOrProvince);

        /// <summary>
        ///
        /// </summary>
        /// <param name="dicType"></param>
        /// <returns></returns>
        DataTable GetDeptByTypeName(string dicType);

        /// <summary>
        ///
        /// </summary>
        /// <param name="ditId"></param>
        /// <returns></returns>
        DataTable GetDicItemByTypeId(int typeId);

        /// <summary>
        /// Gets the dict items by its type.
        /// </summary>
        /// <param name="dicType">Type of the dic item.</param>
        /// <returns>A <see cref="DataTable"/> object.</returns>
        DataTable GetDicItemsByTypeName(string dicType);

        /// <summary>
        /// Gets the CAT/Branch departments.
        /// </summary>
        /// <returns>A <see cref="DataTable"/> object.</returns>
        DataTable GetCATBranchDepartments();

        /// <summary>
        ///
        /// </summary>
        /// <param name="ditId"></param>
        /// <returns></returns>
        DataTable GetDicType();

        /// <summary>
        /// Get Role
        /// </summary>
        /// <returns>AP List</returns>
        DataTable QueryRoleList(string employeeId);

        DataTable QueryDelegationRoleList(string employeeId);

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        DataTable GetAllLegalEntity();

        #endregion

        /// <summary>
        ///
        /// </summary>
        /// <param name="appID">application id</param>
        /// <returns></returns>
        FlowInstance QueryFlowInstance(int appID);

        /// <summary>
        ///
        /// </summary>
        /// <param name="flowID"></param>
        /// <returns></returns>
        FlowInstance QueryFlowInstanceByFlowId(int flowID);

        /// <summary>
        /// Get Delegate
        /// </summary>
        /// <returns>AP List</returns>
        DataTable QueryDelegatedList(string employeeId);

        DataTable QueryAPRate();

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        DataTable QueryAPList();

        /// <summary>
        /// Get Action Point
        /// </summary>
        /// <returns>AP List</returns>
        DataTable QueryAPList(string employeeId);

        /// <summary>
        ///
        /// </summary>
        /// <param name="employeeId"></param>
        /// <param name="applicationNo"></param>
        /// <param name="apNo"></param>
        /// <returns></returns>
        DataTable QueryAPList(string employeeId, string apNo);

        /// <summary>
        ///
        /// </summary>
        /// <param name="employeeId"></param>
        /// <returns></returns>
        DataTable QueryAppNoListWithAP(string employeeId);

        /// <summary>
        ///
        /// </summary>
        /// <param name="AppID"></param>
        /// <returns></returns>
        Application GetApplication(int AppID);

        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        DataTable GetCustomersByName(string name);

        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        CustomerInfo GetCustomerInfoById(int id);

        /// <summary>
        ///
        /// </summary>
        /// <param name="AppID"></param>
        /// <returns></returns>
        CustomerInfo GetCustomerInfo(int AppID);

        /// <summary>
        ///
        /// </summary>
        /// <param name="AppID"></param>
        /// <returns></returns>
        LogisticalInfo GetLogisticalInfo(int AppID);

        /// <summary>
        ///
        /// </summary>
        /// <param name="AppID"></param>
        /// <returns></returns>
        BusinessPurpose GetBusinessPurposeInfo(int AppID);

        /// <summary>
        ///
        /// </summary>
        /// <param name="AppID"></param>
        /// <returns></returns>
        Topic GetTopicInfo(int AppID);

        /// <summary>
        ///
        /// </summary>
        /// <param name="AppID"></param>
        /// <returns></returns>
        SalesTeamInfo GetSalesTeamInfo(int AppID);

        /// <summary>
        ///
        /// </summary>
        /// <param name="AppID"></param>
        /// <returns></returns>
        PaymentInfo GetPaymentInfo(int AppID);

        /// <summary>
        ///
        /// </summary>
        /// <param name="CustomerId"></param>
        /// <returns></returns>
        DataTable GetCustomerAttendeeList(int CustomerId);

        /// <summary>
        ///
        /// </summary>
        /// <param name="AppID"></param>
        /// <returns></returns>
        DataTable GetVisitingSite(int AppID);

        /// <summary>
        ///
        /// </summary>
        /// <param name="PaymentID"></param>
        /// <returns></returns>
        DataTable GetCostCenter(int PaymentID);

        /// <summary>
        ///
        /// </summary>
        /// <param name="flowID"></param>
        /// <returns></returns>
        IList GetDepartmentType(long flowID);

        /// <summary>
        ///
        /// </summary>
        /// <param name="stepName"></param>
        /// <param name="flowType"></param>
        /// <param name="flowID"></param>
        /// <returns></returns>
        DataTable GetRoleAndEmpForStep(string stepName, int flowType, int flowID);

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        DataTable GetDeptHeaders();

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        string GetApplicantDept(string nameEN);

        /// <summary>
        /// AP Owners & Contributers List
        /// </summary>
        DataTable GetAssignedDeptHeaders(int apID, string employeeNo);

        /// <summary>
        /// Get Tasks
        /// </summary>
        /// <returns>Task List</returns>
        DataTable QueryCloseTaskList(string type, string from, string to, string department, string appNo, string status,CCPrincipal currentuser);

        /// <summary>
        /// Get Tasks
        /// </summary>
        /// <returns>Task List</returns>
        DataTable QueryInProcessTaskList(string type, string department, string appNo, string domestic, CCPrincipal employeeNo);
        DataTable QueryDiscardedTaskList(string type, string department, string appNo, string domestic, CCPrincipal employeeNo);
        DataTable QueryRejectedTaskList(string type, string department, string appNo, string domestic, CCPrincipal employeeNo);

        /// <summary>
        /// Get Tasks
        /// </summary>
        /// <returns>Task List</returns>
        DataTable QueryMyParticipationTaskList(string employee, string emproles, string type, string department, string appNo, string status, string year);

        /// <summary>
        ///
        /// </summary>
        /// <param name="AppId"></param>
        /// <returns></returns>
        DataTable GetApplicationActionLog(int AppId);

        /// <summary>
        /// Get Tasks
        /// </summary>
        /// <returns>Task List</returns>
        DataTable QueryPendingTaskList(string type, string department, string appNo, string domestic);

        /// <summary>
        /// Get Tasks
        /// </summary>
        /// <returns>Task List</returns>
        DataTable QueryArchiveTaskList(string type, string department, string appNo, string domestic);

        /// <summary>
        /// Get Tasks
        /// </summary>
        /// <returns>Task List</returns>
        DataTable QueryCancelTaskList(string type, string department, string appNo, string domestic);

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        DataTable GetAllDepartment();

        /// <summary>
        ///
        /// </summary>
        /// <param name="flowID"></param>
        /// <returns></returns>
        Department GetDepartmentByID(int id);

        //=================Joe 2007/6=================
        /// <summary>
        ///
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        //Department GetDepartmentByCode(string code, bool IsProvince);
        Department GetDepartmentByCode(string code);

        Department GetDepartmentByPCAT(string code, bool IsProvince);

        /// <summary>
        /// Get document template, no appid and apid
        /// </summary>
        /// <returns></returns>
        DataTable GetAttachment();

        /// <summary>
        ///
        /// </summary>
        /// <param name="apId"></param>
        /// <returns></returns>
        DataTable GetAttachmentByApId(int apId);

        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        DataTable GetAttachmentByFileId(int id);

        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        DataTable SearchDeptHeaderByName(string name);

        /// <summary>
        ///
        /// </summary>
        /// <param name="role"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        DataTable SearchRoleUsersByName(string role, string name);

        /// <summary>
        /// Check whether AP associated with the Meeting is allowed to start
        /// </summary>
        /// <param name="meetingId"></param>
        /// <returns>true, if meeting is approved, or false</returns>
        bool isAllowAPStart(int meetingId);

        /// <summary>
        /// Check whetehr AP is editable
        /// </summary>
        /// <param name="meetingId"></param>
        /// <returns>true, if not opend at approve meeting minutes step</returns>
        bool isAPEditable(int meetingId);

        //=====================END=======================
        /// <summary>
        ///
        /// </summary>
        /// <param name="appId"></param>
        /// <returns></returns>
        DataTable GetAttachmentByAppId(int appId);

        /// <summary>
        /// transfer tasks
        /// </summary>
        /// <param name="employeeno"></param>
        /// <returns></returns>
        DataTable QueryTransferTaskList(string employeeno);

        /// <summary>
        ///Action Log of the Applicant
        /// </summary>
        /// <param name="appId">Applicant ID</param>
        /// <returns>Action Log list of the Applicant</returns>
        DataTable QueryActionLog(int appId);

        /// <summary>
        /// Get App Type
        /// </summary>
        /// <param name="dicItemKey"></param>
        /// <returns></returns>
        int GetAppTypeID(string dicItemKey);

        /// <summary>
        ///
        /// </summary>
        /// <param name="targetStep"></param>
        /// <param name="appTypeID"></param>
        /// <returns></returns>
        DataTable QueryActionNextSteps(int targetStep, int appTypeID);

        /// <summary>
        /// Get step info from table StepOrder
        /// </summary>
        string GetStepFromStepOrder(int targetStep, int appTypeID);

        /// <summary>
        ///
        /// </summary>
        /// <param name="appId"></param>
        /// <returns></returns>
        DataTable QueryContractInfoByAppId(int appId);

        /// <summary>
        ///
        /// </summary>
        /// <param name="appId"></param>
        /// <returns></returns>
        DataTable QueryCustomerAttendeeByAppId(int appId);

        /// <summary>
        ///
        /// </summary>
        /// <param name="appId"></param>
        /// <returns></returns>
        DataTable QueryALAttendeeByAppId(int appId);

        /// <summary>
        ///
        /// </summary>
        /// <param name="appId"></param>
        /// <returns></returns>
        DataTable QueryCostCenterByAppId(int appId, int type);

        #region Customer

        /// <summary>
        /// Is existed the customer
        /// </summary>
        /// <param name="company"></param>
        /// <param name="namecn"></param>
        /// <returns></returns>
        bool IsExistedCustomer(string company, string namecn, string title);

        /// <summary>
        /// Query customer
        /// </summary>
        /// <param name="company"></param>
        /// <returns></returns>
        DataTable QueryCustomer(string company);

        DataTable GetAccompanyingAttendeeList(int AppID);

        #endregion

        #region CIS

        DataTable GetCustomerFromCIS(string CISName, string CISTitle, string CISCompany, bool domestic);

        DataTable GetApplicationNotInCIS(string AppType);

        //Joe
        DataTable GetCustomerNeedConfirm();

        //--End

        #endregion

        bool HasTravelAgency(long flowId);

        bool IsSSME(long flowId);

        bool IsNeedEVPApproval(long flowId);

        bool BeginFeedback(long flowId);

        string GetCostCenterHead(ISession session, string UserRole, string CodeCenterCode);

        string GetEVP(ISession session, string UserRole);

        string GetOCORoleMemberList(ISession session, string UserRole, string DepartmentCode);

        Department GetDepartmentByCostCenter(string costCenter);

        #region Joan 2007-07-04 for Templates

        DataTable GetTemplates();

        DataTable GetTemplateByID(int templateID);

        #endregion

        #region Joan 2007-08-08 for Meeting Minutes export

        DataTable GetApPartner(int apID, string partner);

        #endregion

        #region Joan 2007-09-06 for get apprequest date

        Nullables.NullableDateTime GetAppRequestDate(int appID);

        #endregion

        //2009-06-12
        int GetCustomerAttendeeCountForOversea(string nameEN, string companyEN);

        DataTable GetCustomerAttendeeAppForOversea(string nameEN, string companyEN);

        //2011-1-30

        //bool IsCountValueOfEntertainmentAndGift(string nameEN, string companyEN);

        /// <summary>
        /// Gift Count (送礼次数)
        /// </summary>
        int GetGiftCount(string nameEN, string companyEN);

        /// <summary>
        /// Entertainment Count (娱乐次数)
        /// </summary>
        int GetEntertainmentCount(string nameEN, string companyEN);

        DataTable GetCostCenterListByPCAT(string pCAT, bool pOrCAT);

        /// <summary>
        /// all type Applicant list
        /// </summary>
        DataTable QueryAllApplicantList(string type, string department, string status, string year, bool isFrist);

        /// <summary>
        /// 获得操作人
        /// </summary>
        string GetActorByAppStep(Application app, string stepName);

        DataTable GetOverseasCustomerFromCIS(string CISName, string CISTitle, string CISCompany);

        /// <summary>
        /// ReportToApprove Log in ActionLog
        /// </summary>
        DataTable GetApplicationActionLogByActionName(int AppId, string actionName);

        DataTable GetAppASBLeadersList(int appId);

        DataTable GetAppASBLeadersList2(int appId);

        bool IsNeedNextLvApprover(long flowId, string stepName);
    }
}
